package com.demo.service.impl;

import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.demo.entity.User;
import com.demo.service.UserService;
import org.springframework.stereotype.Service;

/**
 * @author ：qilong sun
 * @date ：Created in 2020/7/20 9:48
 * @description：通过@SentinelResource注解来标记当前代码为sentinel资源
 * @modified By：
 * @version: V1.0$
 */
@Service
public class UserServiceImpl implements UserService {

    @Override
    public User getUser2(Long uid) {
        throw new RuntimeException("发生异常");
    }

    @Override
    public User getUser(Long uid) {
        // 业务代码
        User user = new User();
        user.setUid(uid);
        user.setName("user-" + uid);
        return user;
    }

    public String exceptionHandler(Long uid, BlockException e) {
        e.printStackTrace();
        return "错误发生在" + uid;
    }
}
